<template>
  <rs-echarts :option="option"></rs-echarts>
</template>
<script>
import charts from './echart-option';

export default {
  name: 'datav-built-in-chart',
  data(){
    return {
      option: {},
      init: false
    }
  },
  props: {
    data: {
      type: Array,
      default: () => []
    },
    widget: {
      type: Object,
      default: null
    }
  },
  watch: {
    data: {
      deep: true,
      handler: function(){
        this.setOption();
      },
      immediate: true
    },
    widget: {
      deep: true,
      handler: function(){
        this.setOption();
      },
      immediate: true
    }
  },
  mounted(){
    // console.log(this.widget , this.data);
  },
  methods: {
    setOption(){
      if(this.widget){
        let type = this.widget.meta.widgetType;

        if(charts[type]){
          let chart = new charts[type](this.widget.meta.privates , this.data , this.widget);
          this.option = chart.option;
        }
        console.log(this.option);
      }
    }
  }
}
</script>